//package com.springboot.study.tests.netty;
//
//import io.netty.bootstrap.Bootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.ChannelInitializer;
//import io.netty.channel.ChannelOption;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.SocketChannel;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//import io.netty.handler.codec.LineBasedFrameDecoder;
//import io.netty.handler.codec.string.StringDecoder;
//
///**
// * @Author: guodong
// * @Date: 2020/12/14 15:15
// * @Version: 1.0
// * @Description:
// */
//public class TimeClient {
//
//    public void connect(int port, String host) throws Exception{
//        // 配置客户端NIO线程组
//        EventLoopGroup group = new NioEventLoopGroup();
//        try {
//            Bootstrap bootstrap = new Bootstrap();
//            bootstrap.group(group).channel(NioServerSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
//                    .handler(new ChannelInitializer<SocketChannel>() {
//                        @Override
//                        protected void initChannel(SocketChannel socketChannel) throws Exception {
//                            // 新增两个解码器 通过使用这两个解码器 可以解决tcp的粘包导致的读半包问题
//                            socketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024));
//                            socketChannel.pipeline().addLast(new StringDecoder());
//                            socketChannel.pipeline().addLast(new TimeClientHandler());
//                        }
//                    });
//
//            // 发起异步链接
//            ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
//            channelFuture.channel().closeFuture().sync();
//        } finally {
//            group.shutdownGracefully();
//        }
//    }
//
//
//    public static void main(String[] args) throws Exception{
//        new TimeClient().connect(8080, "127.0.0.1");
//    }
//
//
//}
